package com.yanfan.energybilling.service.impl;

import com.yanfan.energybilling.domain.EnergrConfiguration;
import com.yanfan.energybilling.mapper.EnergrConfigurationMapper;
import com.yanfan.energybilling.service.EnergrConfigurationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EnergrConfigurationServiceImpl implements EnergrConfigurationService {

    @Autowired
    private EnergrConfigurationMapper energrConfigurationMapper;

    @Override
    public List<EnergrConfiguration> selectByExample(Integer energyTpye,Integer dateTpye,String configurationName,Long configurationId){
        EnergrConfiguration energrConfiguration = new EnergrConfiguration();
        energrConfiguration.setEnergyTpye(energyTpye!=null?energyTpye:-1);
        energrConfiguration.setDateTpye(dateTpye!=null?dateTpye:-1);
        energrConfiguration.setConfigurationName(configurationName);
        energrConfiguration.setConfigurationId(configurationId!=null?configurationId:0L);
        return energrConfigurationMapper.selectByExample(energrConfiguration);
    }

    @Override
    @CacheEvict(value = "energrConfiguration", allEntries = true)
    public int updateEnergrConfiguration(EnergrConfiguration example) {
        return energrConfigurationMapper.updateEnergrConfiguration(example);
    }

    @Override
    @CacheEvict(value = "energrConfiguration", allEntries = true)
    public int deleteEnergrConfiguration(Integer id) {
        return energrConfigurationMapper.deleteEnergrConfiguration(id);
    }

    @Override
    @CacheEvict(value = "energrConfiguration", allEntries = true)
    public int insert(EnergrConfiguration record) {
        return energrConfigurationMapper.insert(record);
    }

    @Override
    @Cacheable(value = "energrConfiguration", key = "#root.methodName + '_' + #serialNumber", unless = "#result == null")
    public List<EnergrConfiguration> selectBySerialNumber(String serialNumber) {
        return energrConfigurationMapper.selectBySerialNumber(serialNumber);
    }

    @Override
    public EnergrConfiguration selectById(Long configurationId) {
        return energrConfigurationMapper.selectById(configurationId);
    }

    @Override
    public int getBuilds(Integer buildsbh, Integer builds2, Integer builds3, Integer builds4) {
        return energrConfigurationMapper.getBuilds(buildsbh,builds2,builds3,builds4);
    }
}
